package com.github.binarylei.zookeeper.auth;


import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.junit.Test;

/**
 * @author: leigang
 * @version: 2018-04-06
 */
public class ZookeeperAuthTest{

    @Test
    public void test1() throws KeeperException, InterruptedException {
        ZookeeperAuth zkAuth = new ZookeeperAuth();
        zkAuth.connect("127.0.0.1", "123456");

        ZooKeeper zk = zkAuth.getZk();
        zk.create("/testAuth", "test".getBytes(), ZooDefs.Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);

        zkAuth.close();
    }

    @Test
    public void test2() throws KeeperException, InterruptedException {
        ZookeeperAuth zkAuth = new ZookeeperAuth();
        zkAuth.connect("127.0.0.1:2181", "1234568");

        ZooKeeper zk = zkAuth.getZk();
        byte[] data = zk.getData("/testAuth", false, null);
        System.out.println(new String(data));

        zkAuth.close();
    }
}
